package com.java2007.hotel.controller.front;

import com.java2007.hotel.constant.Constant;
import com.java2007.hotel.controller.BaseServlet;
import com.java2007.hotel.factory.BeanFactory;
import com.java2007.hotel.pojo.FoodTable;
import com.java2007.hotel.service.FoodTableService;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.List;

/**
 * 处理前端桌子查询
 * @author csl
 * @version V1.0
 * @date 2021/01/25
 **/
@WebServlet("/front/tableServlet")
public class FrontTableServlet extends BaseServlet {
    private FoodTableService foodTableService = (FoodTableService) BeanFactory.getBean(Constant.FOOD_TABLE_SERVICE_IMPL);
    /**
     * 查可用桌子
     * @param req
     * @param resp
     * @return
     */
    public String selectAll(HttpServletRequest req, HttpServletResponse resp){
        HttpSession session = req.getSession();

        List<FoodTable> foodTables = null;
        try {
            foodTables = foodTableService.selectFoodTableByStatus((byte) 0);
        } catch (SQLException e) {
            e.printStackTrace();
            return "back:" + "服务器错误%"+"frontindex.jsp";
        }
        session.setAttribute("foodTables",foodTables);
        return "redirect:"+req.getContextPath()+"/front/index.jsp";
    }
}
